import Vue from 'vue';
import VueRouter from 'vue-router';
// 点击跳转同一个路径
// 在VueRouter上配置路由跳转，在router中的index.js中加上以下代码，注意加在use之前
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
    return routerPush.call(this, location).catch(err => { })
};


Vue.use(VueRouter);
import Layout from '@/views/Layout';
import Login from '@/views/Login';
import Home from '@/views/Home';
// 产品管理
import GoodsManage from '@/views/GoodsManage';
import List from '@/views/GoodsManage/List';
import Category from '@/views/GoodsManage/Category';
// 订单管理
import OrderManage from '@/views/OrderManage';
import OrderList from '@/views/OrderManage/List';
import Collect from '@/views/OrderManage/Collect';
import Auditing from '@/views/OrderManage/Auditing';
import AddGoods from '@/views/GoodsManage/List/AddGoods';

// 广告管理
import Advert from '@/views/Advert';
import AdvertList from '@/views/Advert/List';
// 系统管理
import SystemManage from '@/views/SystemManage';
import department from '@/views/SystemManage/department';
import role from '@/views/SystemManage/role';


const menuList = [
    {
        path: '/goods',
        name: 'goods',
        component: GoodsManage,
        meta: {
            title: '产品管理',
        },
        redirect: '/goods/list',
        children: [
            {
                path: 'list',
                name: 'list',
                component: List,
                meta: {
                    title: '产品列表',
                },
            },
            {
                path: 'category',
                name: 'category',
                component: Category,
                meta: {
                    title: '产品分类',
                },
            },
            {
                path: 'addgoods',
                name: 'addgoods',
                component: AddGoods,
                // 路由元信息
                meta: {
                    activeMenu: '/goods/list'
                }
            }
        ]
    },
    {
        path: '/order',
        name: 'order',
        component: OrderManage,
        meta: {
            title: '订单管理',
        },
        redirect: '/order/list',
        children: [
            {
                path: 'list',
                name: 'orderlist',
                component: OrderList,
                meta: {
                    title: '订单列表',
                },
            },
            {
                path: 'collect',
                name: 'collect',
                component: Collect,
                meta: {
                    title: '汇总清单',
                },
            },
            {
                path: 'auditing',
                name: 'auditing',
                component: Auditing,
                meta: {
                    title: '订单审核',
                },
            }
        ]
    },
    {
        path: '/advert',
        name: 'advert',
        component: Advert,
        meta: {
            title: '广告分类',
        },
        redirect: '/advert/list',
        children: [
            {
                path: 'list',
                name: 'advertlist',
                component: AdvertList,
                meta: {
                    title: '广告列表',
                },
            },
        ]
    },
    {
        path: '/system',
        name: 'system',
        component: SystemManage,
        redirect: '/system/role',
        meta: {
            title: "系统管理"
        },
        children: [
            {
                path: 'role',
                name: 'role',
                component: role,
                meta: {
                    title: "角色管理"
                },
            },
            {
                path: 'department',
                name: 'department',
                component: department,
                meta: {
                    title: "部门管理"
                },
            }
        ]
    },
]
export const baseRoutes = [
    {
        path: '/',
        component: Layout,
        meta: {
            // title: '首页',
            isLogin: true
        },
        children: [
            {
                path: '/',
                name: 'home',
                component: Home,
                meta: {
                    title: '首页',
                },
            },
            
        ]
    },
];

export const routes = [
    {
        path: '/login',
        name: 'login',
        component: Login
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router;